package com.tc.multicast;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.LinkedList;
import java.util.List;

import com.tc.gateway.tunnel.TunnelServer;



public class NativeTunnelServer implements TunnelServer {
	
	Multicast core;
	OutputStream stream;

	public NativeTunnelServer(final OutputStream stream) {
		core = new Multicast("228.9.6.9",(short)9999,"228.9.6.8",(short)8888, "", (short)10000);
		this.stream = stream;
	}

	public boolean started(){
		return true;
	}
	/* (non-Javadoc)
	 * @see com.tc.assistance.tunnel.TunnelOutput#write(byte[], int, int)
	 */
	public void write(byte[] buffer, int offset, int len){
		


	}
	public void stop(){
		
	}
	Thread ts;
	public void start(){
		ts = new Thread(){

			@Override
			public void run() {
				
				super.run();
				
				try {
				    byte[] buf = new byte[1024];

	                


					while(true){
						  byte[] data = core.receive();
						   stream.write(buf);

					}
				} catch (Exception e) {
					// TODO Auto-generated catch block
					System.out.println(e.getMessage());
				}
			}
			
		};
		ts.start();
	}
	
}
